import java.util.HashMap;
import java.util.HashSet;

class Solution1 {
    public String intToRoman(int num) {
        String[] thousands = {"","M","MM","MMM"};
        String[] hundreds = {"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
        String[] tens = {"", "X", "XX","XXX","XL","L","LX","LXX","LXX","XC"};
        String[] ones = {"","I","II","III","IV","V","VI","VII","VIII","IX"};
        return thousands[num/1000] + hundreds[num%1000/100] + tens[num%100/10] + ones[num%10];
    }
}


class Solution {
    public int romanToInt(String s) {
        HashMap<Character,Integer> map = new HashMap<>();
        map.put('I',1);
        map.put('V',5);
        map.put('X',10);
        map.put('L',50);
        map.put('C',100);
        map.put('D',500);
        map.put('M',1000);
        int ans = 0;
        for(int i = 0; i<s.length(); i++) {
            if(i+1 < s.length() && map.get(s.charAt(i)) < map.get(s.charAt(i+1))) {
                ans += map.get(s.charAt(i));
            }else {
                ans -= map.get(s.charAt(i));
            }
        }
        return ans;
    }
}

public class Test {


}
